﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using TMPro;

public class GameManager : MonoBehaviour
{
    public Rigidbody2D rigidPlayer;
    public GameObject audioManager;
    public GameObject resultWindow;
    public GameObject readyWindow;
    public TextMeshProUGUI scoreText;
    public int score;
    public bool isLose = false;

    private void Start()
    {
        if (FindObjectOfType<AudioSource>() == null)
        {
            Instantiate(audioManager);
        }
    }

    private void Update()
    {
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            Application.Quit();
        }
        if (Input.GetKeyDown(KeyCode.Return))
        {
            readyWindow.SetActive(false);
            rigidPlayer.constraints = RigidbodyConstraints2D.FreezePositionX | RigidbodyConstraints2D.FreezeRotation;
        }
        if (isLose)
        {
            resultWindow.SetActive(true);
            scoreText.text = "Score : " + score;
            if (Input.GetKeyDown(KeyCode.Return))
            {
                SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
            }
        }
    }
}
